#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm

import sys


def student_management_menu():
    while True:
        print('1. 增加学生信息')
        print('2. 根据学生学号删除信息')
        print('3. 根据学生姓名查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            sno = input("请输入学生学号:")
            sname = input("请输入学生姓名:")
            ssex = input("请输入学生性别:")
            sage = input("请输入学生年龄:")
            dno = input("请输入所属院系:")
            sclass = input("请输入班级:")
            address = input("请输入家庭住址:")
            from dao.student_dao import insert_student
            from models.student_model import Student
            student = Student(sno, sname, ssex, sage, dno, sclass, address)
            insert_student(student)
        elif index_sql == '2':
            sno = input("请输入要删除的学生学号:")
            from dao.student_dao import delete_student_by_sno
            delete_student_by_sno(sno)
        elif index_sql == '3':
            name = input("请输入要查询的学生姓名:")
            from dao.student_dao import query_students_by_name
            students = query_students_by_name(name)
            for student in students:
                print(f"学号: {student.sno}, 姓名: {student.sname}, 性别: {student.ssex}, 年龄: {student.sage}, 所属院系: {student.dno}, 班级: {student.sclass}, 家庭住址: {student.address}")
        else:
            print("输入的操作指令无效，请重新输入")


def course_management_menu():
    while True:
        print('1. 增加课程信息')
        print('2. 根据课程编号删除信息')
        print('3. 根据课程名称查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            cno = input("请输入课程编号:")
            cname = input("请输入课程名称:")
            chours = input("请输入学时:")
            credit = input("请输入学分:")
            tno = input("请输入教师编号:")
            student_count = input("请输入学生选课人数:")
            from dao.course_dao import insert_course
            from models.course_model import Course
            course = Course(cno, cname, chours, credit, tno, student_count)
            insert_course(course)
        elif index_sql == '2':
            cno = input("请输入要删除的课程编号:")
            from dao.course_dao import delete_course_by_cno
            delete_course_by_cno(cno)
        elif index_sql == '3':
            cname = input("请输入要查询的课程名称:")
            from dao.course_dao import query_courses_by_name
            courses = query_courses_by_name(cname)
            for course in courses:
                print(f"课程编号: {course.cno}, 课程名称: {course.cname}, 学时: {course.chours}, 学分: {course.credit}, 教师编号: {course.tno}, 学生选课人数: {course.student_count}")
        else:
            print("输入的操作指令无效，请重新输入")


def teacher_management_menu():
    while True:
        print('1. 增加教师信息')
        print('2. 根据教师编号删除信息')
        print('3. 根据教师姓名查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            tno = input("请输入教师编号:")
            tname = input("请输入教师姓名:")
            dno = input("请输入所属院系:")
            salary = input("请输入工资:")
            tmobile = input("请输入教师手机号:")
            from dao.teacher_dao import insert_teacher
            from models.teacher_model import Teacher
            teacher = Teacher(tno, tname, dno, salary, tmobile)
            insert_teacher(teacher)
        elif index_sql == '2':
            tno = input("请输入要删除的教师编号:")
            from dao.teacher_dao import delete_teacher_by_tno
            delete_teacher_by_tno(tno)
        elif index_sql == '3':
            tname = input("请输入要查询的教师姓名:")
            from dao.teacher_dao import query_teachers_by_name
            teachers = query_teachers_by_name(tname)
            for teacher in teachers:
                print(f"教师编号: {teacher.tno}, 姓名: {teacher.tname}, 所属院系: {teacher.dno}, 工资: {teacher.salary}, 教师手机号: {teacher.tmobile}")
        else:
            print("输入的操作指令无效，请重新输入")


def class_management_menu():
    while True:
        print('1. 增加班级信息')
        print('2. 根据班级编号删除信息')
        print('3. 根据班级名称查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            classid = input("请输入班级编号:")
            classname = input("请输入班级名称:")
            from dao.class_dao import insert_class
            from models.class_model import Class
            class_obj = Class(classid, classname)
            insert_class(class_obj)
        elif index_sql == '2':
            classid = input("请输入要删除的班级编号:")
            from dao.class_dao import delete_class_by_id
            delete_class_by_id(classid)
        elif index_sql == '3':
            classname = input("请输入要查询的班级名称:")
            from dao.class_dao import query_classes_by_name
            classes = query_classes_by_name(classname)
            for class_obj in classes:
                print(f"班级编号: {class_obj.classid}, 班级名称: {class_obj.classname}")
        else:
            print("输入的操作指令无效，请重新输入")


def department_management_menu():
    while True:
        print('1. 增加院系信息')
        print('2. 根据院系编号删除信息')
        print('3. 根据院系名称查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            id = input("请输入院系编号:")
            pid = input("请输入父级院系编号（若无则输入空值）:")
            name = input("请输入院系名称:")
            from dao.department_dao import insert_department
            from models.department_model import Department
            department = Department(id, pid, name)
            insert_department(department)
        elif index_sql == '2':
            id = input("请输入要删除的院系编号:")
            from dao.department_dao import delete_department_by_id
            delete_department_by_id(id)
        elif index_sql == '3':
            name = input("请输入要查询的院系名称:")
            from dao.department_dao import query_departments_by_name
            departments = query_departments_by_name(name)
            for department in departments:
                print(f"院系编号: {department.id}, 父级院系编号: {department.pid}, 院系名称: {department.name}")
        else:
            print("输入的操作指令无效，请重新输入")


def dept_management_menu():
    while True:
        print('1. 增加院系信息')
        print('2. 根据院系编号删除信息')
        print('3. 根据院系名称查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            dno = input("请输入院系编号:")
            dname = input("请输入院系名称:")
            dean = input("请输入系主任:")
            from dao.dept_dao import insert_dept
            from models.dept_model import Dept
            dept_obj = Dept(dno, dname, dean)
            insert_dept(dept_obj)
        elif index_sql == '2':
            dno = input("请输入要删除的院系编号:")
            from dao.dept_dao import delete_dept_by_dno
            delete_dept_by_dno(dno)
        elif index_sql == '3':
            dname = input("请输入要查询的院系名称:")
            from dao.dept_dao import query_depts_by_name
            depts = query_depts_by_name(dname)
            for dept_obj in depts:
                print(f"院系编号: {dept_obj.dno}, 院系名称: {dept_obj.dname}, 系主任: {dept_obj.dean}")
        else:
            print("输入的操作指令无效，请重新输入")


def sc_management_menu():
    while True:
        print('1. 增加选课记录信息')
        print('2. 根据学号和课程编号删除选课记录信息')
        print('3. 根据学号查询选课记录信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令:')
        if index_sql == '0':
            break
        elif index_sql == '1':
            sno = input("请输入学号:")
            cno = input("请输入课程编号:")
            score = input("请输入成绩（若暂无成绩可输入空值）:")
            from dao.sc_dao import insert_sc
            from models.sc_model import Sc
            sc_obj = Sc(sno, cno, score)
            insert_sc(sc_obj)
        elif index_sql == '2':
            sno = input("请输入要删除选课记录的学号:")
            cno = input("请输入要删除选课记录的课程编号:")
            from dao.sc_dao import delete_sc_by_sno_cno
            delete_sc_by_sno_cno(sno, cno)
        elif index_sql == '3':
            sno = input("请输入要查询选课记录的学号:")
            from dao.sc_dao import query_sc_by_sno
            scs = query_sc_by_sno(sno)
            for sc in scs:
                print(f"学号: {sc.sno}, 课程编号: {sc.cno}, 成绩: {sc.score}")
        else:
            print("输入的操作指令无效，请重新输入")


def main_menu():
    while True:
        print('1. 学生信息管理')
        print('2. 课程信息管理')
        print('3. 教师信息管理')
        print('4. 班级信息管理')
        print('5. 院系信息管理（department表）')
        print('6. 院系信息管理（dept表）')
        print('7. 选课记录信息管理')
        print('0. 退出')
        index = input('请输入操作菜单选项:')
        if index == '0':
            sys.exit(0)
        elif index == '1':
            student_management_menu()
        elif index == '2':
            course_management_menu()
        elif index == '3':
            teacher_management_menu()
        elif index == '4':
            class_management_menu()
        elif index == '5':
            department_management_menu()
        elif index == '6':
            dept_management_menu()
        elif index == '7':
            sc_management_menu()
        else:
            print("输入的选项无效，请重新输入")


if __name__ == '__main__':
    main_menu()